//
//  XJGoodsDetailCommentHeader.m
//  XinJiangMall
//
//  Created by Tzyang on 2018/4/11.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJGoodsDetailCommentHeader.h"

@interface XJGoodsDetailCommentHeader ()

@property (nonatomic ,strong) UILabel * xjgdCommentLab;
@property (nonatomic ,strong) UILabel * xjgdGoodCommentLab;
@property (nonatomic ,strong) UIButton * xjgdAllCommentBtn;

@end

@implementation XJGoodsDetailCommentHeader

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = WHITE_COLOR;

        [self setupSubviews];
    }
    return self;
}

- (UILabel *)xjgdCommentLab{
    if (!_xjgdCommentLab) {
        UILabel * xjgdCommentLab = [UILabel new];
        self.xjgdCommentLab = xjgdCommentLab;
        [self addSubview:xjgdCommentLab];
    }
    return _xjgdCommentLab;
}

- (UILabel *)xjgdGoodCommentLab{
    if (!_xjgdGoodCommentLab) {
        UILabel * xjgdGoodCommentLab = [UILabel new];
        self.xjgdGoodCommentLab = xjgdGoodCommentLab;
        [self addSubview:xjgdGoodCommentLab];
    }
    return _xjgdGoodCommentLab;
    
}

- (UIButton *)xjgdAllCommentBtn{
    if (!_xjgdAllCommentBtn) {
        UIButton * xjgdAllCommentBtn = [UIButton new];
        self.xjgdAllCommentBtn = xjgdAllCommentBtn;
        [self addSubview:xjgdAllCommentBtn];
    }
    return _xjgdAllCommentBtn;
    
}

- (void)setupSubviews{
    
    self.xjgdCommentLab.font = XJFONTSET_M(16);
    self.xjgdCommentLab.textColor = XJCOLOR_RGB(17, 17, 17);
    self.xjgdCommentLab.text = @"商品评价";
    CGFloat xjgdCommentLabW = [UILabel labelWithLabel:self.xjgdCommentLab
                                 getWidthWithTitle:self.xjgdCommentLab.text
                                              font:self.xjgdCommentLab.font];
    CGFloat xjgdCommentLabH = [UILabel labelWithLabel:self.xjgdCommentLab
                                  getHeightByWidth:xjgdCommentLabW
                                             title:self.xjgdCommentLab.text
                                              font:self.xjgdCommentLab.font];
    self.xjgdCommentLab.sd_layout
    .leftSpaceToView(self, ADAPTWidth(12))
    .centerYEqualToView(self)
    .widthIs(xjgdCommentLabW)
    .heightIs(xjgdCommentLabH);
    
    
    CGSize xjgdAllCommentBtnSize = [UIButton getSizeFromButtonTitle:@"查看全部(322)" Font:XJFONTSET_R(12)];
    [self.xjgdAllCommentBtn buttonWithTitle:@"查看全部(322)" titleFont:XJFONTSET_R(12) titleColor:XJCOLOR_RGB(112, 130, 133) imageType:ImageTypeImg imageName:@"direction_right_gray" withTarget:self action:@selector(xjgdAllCommentBtnClick:) style:ImgTextBtnStyleRight margin:15];
    self.xjgdAllCommentBtn.sd_layout
    .rightSpaceToView(self, ADAPTWidth(15))
    .centerYEqualToView(self)
    .widthIs(xjgdAllCommentBtnSize.width+20)
    .heightIs(xjgdAllCommentBtnSize.height);
    
    self.xjgdGoodCommentLab.font = XJFONTSET_R(12);
    self.xjgdGoodCommentLab.textColor = XJCOLOR_RGB(244, 67, 54);
    self.xjgdGoodCommentLab.text = @"好评率91%";
    CGFloat xjgdGoodCommentLabW = [UILabel labelWithLabel:self.xjgdGoodCommentLab
                                        getWidthWithTitle:self.xjgdGoodCommentLab.text
                                                     font:self.xjgdGoodCommentLab.font];
    CGFloat xjgdGoodCommentLabbH = [UILabel labelWithLabel:self.xjgdGoodCommentLab
                                          getHeightByWidth:xjgdGoodCommentLabW
                                                     title:self.xjgdGoodCommentLab.text
                                                      font:self.xjgdGoodCommentLab.font];
    self.xjgdGoodCommentLab.sd_layout
    .rightSpaceToView(self.xjgdAllCommentBtn, ADAPTWidth(1))
    .centerYEqualToView(self)
    .widthIs(xjgdGoodCommentLabW)
    .heightIs(xjgdGoodCommentLabbH);
    
}

- (void)xjgdAllCommentBtnClick:(UIButton *)sender{
    
    if (_delegate && [_delegate respondsToSelector:@selector(moreViewAllCommentAction)]) {
        [_delegate moreViewAllCommentAction];
    }
}


@end
